<template>
  <div class="container">
    <div class="left">资金后台管理</div>
    <div class="mian"></div>
    <div class="right">
      <span>欢迎 </span>
      <el-dropdown trigger="click" @command="setDialogInfo">
        <span class="el-dropdown-link">{{user.name}}
          <i class="el-icon-arrow-down el-icon--right"></i>
        </span>
        <el-dropdown-menu slot="dropdown">
          <el-dropdown-item command='personal'>个人信息</el-dropdown-item>
          <el-dropdown-item command='logout'>退出登录</el-dropdown-item>
        </el-dropdown-menu>
      </el-dropdown>
    </div>
  </div>
</template>
<script>
export default {
  name:'Header',
  computed: {
    user() {
      return this.$store.getters.user;
    }
  },
  methods: {
    setDialogInfo(cmditem) {
      if (!cmditem) {
        console.log("test");
        this.$message("菜单选项缺少command属性");
        return;
      }
      switch (cmditem) {
        case "personal":
          this.showInfoList();
          break;
        case "logout":
          this.logout();
          break;
      }
    },
    showInfoList() {
      // 个人信息
      this.$router.push("/personal");
    },
    logout() {
      // 清除token
      localStorage.removeItem("FundToken");
      this.$store.dispatch("clearCurrentState");

      // 页面跳转
      this.$router.push("/login");
    }
  }
};
</script>

<style lang="less" scope>
.container {
  height: 50px;
  line-height: 50px;
  border-bottom: 1px solid #ccc;
  display: flex;
}
.left {
  width: 200px;
  padding-left: 30px;
  font-weight: bold;
  color: #409eff;
}
.mian {
  flex: 1;
}
.right {
  float: right;
}
.el-dropdown-link {
  cursor: pointer;
  color: #409eff;
}
.el-icon-arrow-down {
  font-size: 12px;
}
</style>